package com.dl.controller;

import com.dl.dao.TeacherMapper;
import com.dl.pojo.Teacher;
import com.dl.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @RequestMapping("/teacher_login.action")
    public ModelAndView teacher_login(Teacher teacher,ModelAndView mav){
        List<Teacher> teachers=teacherService.getTeachers(teacher);
        if (teachers.isEmpty()){
            //failed
            mav.setViewName("fail.jsp");
        }else{
            mav.addObject("teacher",teachers.get(0));
            mav.setViewName("success.jsp");
        }
        return mav;
    }
}
